//
//  SplashVC.m
//  CJModileAdDemo
//
//  Created by CJ on 2022/3/7.
//

#import "SplashVC.h"
#import "CustomShowView.h"
#import <WindMillSDK/WindMillSplashAd.h>
#import <WindMillSDK/WindMillAdRequest.h>
#import <WindMillSDK/WindMillConstant.h>


@interface SplashVC ()<WindMillSplashAdDelegate>

@property (nonatomic, strong) WindMillSplashAd *splashAd;

@end

@implementation SplashVC

@synthesize customView = _customView;

- (void)viewDidLoad {
    [super viewDidLoad];
    [self setupUI];
}

- (void)dealloc
{
    NSLog(@"事件:%s", __FUNCTION__);
}

- (void)loadAdData {
    WindMillAdRequest *request = [WindMillAdRequest request];
    request.placementId = @"9775258296837928";
    request.userId = @"user_id";

    CGFloat bottomHeight =  100;
    CGSize adSize = CGSizeMake(self.navigationController.view.bounds.size.width, self.navigationController.view.bounds.size.height-bottomHeight);

    NSDictionary *extra = @{kWindMillSplashExtraAdSize: NSStringFromCGSize(adSize)};

    self.splashAd = [[WindMillSplashAd alloc] initWithRequest:request extra:extra];
    self.splashAd.delegate = self;
    self.splashAd.rootViewController = self;

    UIView *bottomView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, [UIScreen mainScreen].bounds.size.width, 64)]; //自定义底部View
    bottomView.backgroundColor = [UIColor redColor];
    [self.splashAd loadAdAndShowWithBottomView:bottomView];
}

- (void)setupUI {
    self.title = @"SplashAd";
    [self.view addSubview:self.customView];
    self.customView.frame = CGRectMake(0, 100, 200, 200);
    self.customView.center = self.view.center;
}

- (void)handleEvent:(NSInteger)eve {
    if (eve == 0) {
        NSLog(@"事件:%s", __FUNCTION__);
        [self loadAdData];
        return;
    }
//    self.splashAd loadAdAndShowWithBottomView:<#(UIView * _Nullable)#>
}

- (CustomShowView *)customView {
    if (!_customView) {
        _customView = [[CustomShowView alloc] init];
        __weak SplashVC *weakSelf = self;
        _customView.event = ^(NSInteger eve) {
            [weakSelf handleEvent:eve];
        };
    }
    return _customView;
}

- (void)onSplashAdDidLoad:(WindMillSplashAd *)splashAd {
    NSLog(@"事件:%s", __FUNCTION__);
}

-(void)onSplashAdLoadFail:(WindMillSplashAd *)splashAd error:(NSError *)error {
    NSLog(@"事件:%s", __FUNCTION__);
}

-(void)onSplashAdSuccessPresentScreen:(WindMillSplashAd *)splashAd {
    NSLog(@"事件:%s", __FUNCTION__);
}

- (void)onSplashAdClicked:(WindMillSplashAd *)splashAd {
    NSLog(@"事件:%s", __FUNCTION__);
}

- (void)onSplashAdWillClosed:(WindMillSplashAd *)splashAd {
    NSLog(@"事件:%s", __FUNCTION__);
}

- (void)onSplashAdClosed:(WindMillSplashAd *)splashAd {
    NSLog(@"事件:%s", __FUNCTION__);
}

- (void)splashAd:(WindMillSplashAd *)splashAd didFailToLoadADSource:(WindMillAdInfo *)adInfo error:(NSError *)error {
    NSLog(@"事件:%s", __FUNCTION__);
}

@end
